<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>

<body>
    <h1>首页</h1>
</body>
<script>
    $(function () {
        // 获取令牌
        let token = localStorage.getItem('token');

        $.ajax({
            // 请求路径
            url: `http://localhost:8080/findById`,
            // 请求方式
            type: "get",
            // 设置请求头
            headers: {
                "auth": token
            },
            // 请求成功的回调函数
            success: function (data) {
                if (data.code == 200) {
                    alert("欢迎回来" + data.data);
                } else if (data.code == 401) {
                    window.location.href = "login.html";
                }
            }
        })
    })
</script>

</html>